package com.dfbz;

import com.dfbz.entity.User;
import com.dfbz.mapper.UserMapperMaster;
import com.dfbz.mapper.UserMapperSlave;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
@SpringBootTest(classes = MyBatisPlusApplication.class)
@RunWith(SpringRunner.class)
public class Demo01_测试多数据源 {

    @Autowired
    private UserMapperMaster userMapperMaster;

    @Autowired
    private UserMapperSlave userMapperSlave;


    @Test
    public void test1() {

        // 使用的是master数据源
        List<User> userList = userMapperMaster.selectList(null);
        for (User user : userList) {
            System.out.println(user);
        }
    }
    @Test
    public void test2() {
        // 使用slave数据源
        List<User> userList = userMapperSlave.selectList(null);
        for (User user : userList) {
            System.out.println(user);
        }
    }
}

